package org.stw.bullfrog.ui.managers
{
	import mx.events.DragEvent;

	/*
	可以视作各类视图Manager的一个工厂
	*/
	
	public class UIManager extends Object
	{
		//将这些变量声明为Object而不是Class可以巧妙的实现每个Manager的单例模式
		private static var _toolTip:Object = ToolTipManager;
		private static var _popUp:Object = PopUpManager;
		private static var _mouse:Object = MouseManager;
		private static var _drag:Object = DragManager;
		private static var _language:Object = LanguageManager;
		private static var _sound:Object = SoundManager;
		private static var _fullScreen:Object = FullScreenManager;
		
		public function UIManager()
		{
			super();
		}
		
		public static function registerToolTipManager(c:Class):void
		{
			_toolTip = c;
		}
		
		public static function getToolTipManager():ToolTipManager
		{
			_toolTip = getInstance(_toolTip);
			return _toolTip;
		}
		
		public static function registerPopUpManager(c:Class):void
		{
			_popUp = c;
		}
		
		public static function getPopUpManager():PopUpManager
		{
			_popUp = getInstance(_popUp);
			return _popUp;
		}
		
		public static function registerMouseManager(c:Class):void
		{
			_mouse = c;
		}
		
		public static function getMouseManager():MouseManager
		{
			_mouse = getInstance(_mouse);
			return _mouse;
		}
		
		public static function registerDragManager(c:Class):void
		{
			_drag = c;
		}
		
		public static function getDragManager():DragManager
		{
			_drag = getInstance(_drag);
			return _drag;
		}
		
		public static function registerLanguageManager(c:Class):void
		{
			_language = c;
		}
		
		public static function getLanguageManager():LanguageManager
		{
			_language = getInstance(_language);
			return _language;
		}
		
		public static function registerSoundManager(c:Class):SoundManager
		{
			_sound = c;
		}
		
		public static function getSoundManager():SoundManager
		{
			_sound = getInstance(_sound);
			return _sound;
		}
		
		public static function registerFullScreenManager(c:Class):FullScreenManager
		{
			_fullScreen = c;
		}
		
		public static function getFullScreenManager():FullScreenManager
		{
			_fullScreen = getInstance(_fullScreen);
			return _fullScreen;
		}
		
		//o参数的类型如果是Class，则说明为第一次注册，创建实例；如果o是实例则说明已经注册过，返回之前的实例。确保为单例。
		private static function getInstance(o:*):*
		{
			if(o == null){
				return null;
			}
			if(o is Class){
				return new c();
			}
			return o;
		}
	}
}